package com.example.snackfood.controller;

import com.example.snackfood.entity.Products;
import com.example.snackfood.services.IsnackFoodProductsService;
import com.example.snackfood.services.impl.SnackFoodProductsService;
import com.example.snackfood.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-24 21:43
 **/


@RestController
@RequestMapping("/Products")
public class SnackFoodProductsController {


    @Autowired
    private IsnackFoodProductsService snackFoodProductsService;

    @PostMapping("/saveProduct")
    public R saveProducts(@RequestBody  Products products) {
        snackFoodProductsService.save(products);
        return R.success("添加成功");
    }
    //删：
    @DeleteMapping ("/deleteProduct/{id}")
    public R deleteProducts(@PathVariable Long id){
        snackFoodProductsService.delete(id);
        return R.success("删除成功");
    }

    //改：
    @PutMapping("/updateProduct")
    public R updateProducts(@RequestBody Products products){
        snackFoodProductsService.update(products);
        return R.success(products);
    }

    //查（条件查询）：
    @GetMapping("/getProduct")
    public Products getBooks(@RequestBody Products products){return snackFoodProductsService.getProducts(products);}

    //查询全部：
    @GetMapping("/findAllProduct")
    public List<Products> findAll(){
        return snackFoodProductsService.findAllProducts();
    }
}
